require "dionysus/redcarpet"

module Dionysus
  module Redcarpet
    # This is an extension to Redcarpet that preprocesses a file as simple plaintext, simply
    # wrapping the document in fenced code blocks (i.e. triple-backticks).
    module Plaintext
      extend ActiveSupport::Concern

      included do
        preprocess_file do |renderer, full_document|
          if full_document =~ FILE_DIRECTIVE_REGEXP
            if $1 == "md" and $2 == "plaintext"
              full_document = "```\n#{full_document.gsub(FILE_DIRECTIVE_REGEXP, "")}\n```"
            end
          end
          full_document
        end
      end
    end
  end
end

Redcarpet::Render::HTML.send(:include, Dionysus::Redcarpet::Plaintext)
